const DirectusClient = require('./src/config/directus');
const logger = require('./src/utils/logger');

async function testDirectusConnection() {
  const client = new DirectusClient();
  
  try {
    logger.info('测试 Directus 连接...');
    
    // 测试获取商品
    try {
      const products = await client.getProducts();
      logger.info(`成功获取 ${products.length} 个商品`);
      if (products.length > 0) {
        logger.info('商品示例:', JSON.stringify(products[0], null, 2));
      }
    } catch (error) {
      logger.error('获取商品失败:', error.message);
    }
    
    // 测试获取配置
    try {
      const settings = await client.getOrderSettings();
      logger.info(`成功获取 ${settings.length} 个配置`);
      if (settings.length > 0) {
        logger.info('配置示例:', JSON.stringify(settings[0], null, 2));
      }
    } catch (error) {
      logger.error('获取配置失败:', error.message);
    }
    
  } catch (error) {
    logger.error('Directus 连接测试失败:', error);
  }
}

testDirectusConnection();